﻿using MD5Hash;
using MediatR;
using MS.Data.API.Write.Applicant.Command.User;
using MS.Data.Domain;
using MS.Data.ErrorCode;
using MS.Data.Infratructrue.Istanbul;

namespace MS.Data.API.Write.Applicant.CommandHandel.User
{
    public class AddUserCommandHandel:IRequestHandler<AddUserCommand,APIResult<int>>
    {
        IBaseRepository<Domain.User> userRep;
        private readonly IBaseRepository<Role> repository;

        public AddUserCommandHandel(IBaseRepository<Domain.User> userRep,IBaseRepository<Role> repository)
        {
            this.userRep = userRep;
            this.repository = repository;
        }

        public async Task<APIResult<int>> Handle(AddUserCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>();
            result.code=APIEnum.添加成功;
            result.mes = APIEnum.添加成功.ToString();
            var mi = request.user.UserPwd.GetMD5();
            request.user.UserPwd = mi;
            await userRep.Add(request.user);

            return await Task.FromResult(result);

        }
    }
}
